package game.Player;

import game.Helper;

import java.util.ArrayList;
import java.util.List;

public class TeamController {
    private Team team;
    private List<Controller> controllerList;

    public TeamController(Team team) {
        controllerList = new ArrayList<>();
        this.team = team;
    }

    public void setTeam(Team team) {
        this.team = team;
    }

    public Team getTeam() {
        return this.team;
    }

    public List<Controller> getControllers() {
        return this.controllerList;
    }

    public void addController(Controller controller) {
        this.controllerList.add(controller);
    }

    public void requestHelp(Player p) {
        BotController closest = null;
        int distance = Integer.MAX_VALUE;
        for (Controller c : controllerList) {
            if (c instanceof BotController) {
                if (c.player != p &&!((BotController) c).isBusy()) {
                    int d = Helper.mainScene.getMap().a_star(p.getPosition(), c.player.getPosition()).size();
                    if (d < distance) {
                        distance = d;
                        closest = (BotController) c;
                    }
                }
            }
        }
        if (closest != null) closest.sendHelp(p);
    }
}
